package co.yiiu.pybbs.config;

import cn.stylefeng.roses.file.FileOperator;
import cn.stylefeng.roses.file.modular.aliyun.AliyunFileOperator;
import cn.stylefeng.roses.file.modular.aliyun.prop.AliyunOssProperties;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 文件存储的配置
 * <p>
 * 默认激活本地文件存储
 *
 * @author fengshuonan
 * @date 2020/6/6 22:27
 */
@Configuration
public class FileConfig {

    /**
     * 默认文件存储的位置
     */
    public static final String DEFAULT_BUCKET = "guns-bbs";

    @Value("${oss.key}")
    private String ossKey;

    @Value("${oss.secret}")
    private String ossSecret;

    @Value("${oss.endPoint}")
    private String endPoint;

    /**
     * 阿里云文件存储
     *
     * @author fengshuonan
     * @date 2020/6/9 21:39
     */
    @Bean
    public FileOperator aliyunFileOperator() {
        AliyunOssProperties aliyunOssProperties = new AliyunOssProperties();
        aliyunOssProperties.setEndPoint(endPoint);
        aliyunOssProperties.setAccessKeyId(ossKey);
        aliyunOssProperties.setAccessKeySecret(ossSecret);
        return new AliyunFileOperator(aliyunOssProperties);
    }

}
